package fi.saarinen.loader.elf;

import java.io.IOException;

/**
 * 
 * @author jsaarinen
 */
public class SectionHeader implements Loader
{
  private int shName;
  private int shType;
  private int shFlags;
  private int shAddr;
  private int shOffset;
  private int shSize;
  private int shLink;
  private int shInfo;
  private int shAddrAlign;
  private int shEntSize;
      
  public SectionHeader()
  {
    
  }

  /* (non-Javadoc)
   * @see fi.saarinen.loader.elf.Loader#load(java.io.DataInputStream)
   */
  public int load(final byte[] mem, int offset) throws ELFException
  {
    this.shName = IO.readWord(mem, offset);
    offset += 4;
    
    this.shType = IO.readWord(mem, offset);
    offset += 4;

    this.shFlags = IO.readWord(mem, offset);
    offset += 4;

    this.shAddr = IO.readAddr(mem, offset);
    offset += 4;

    this.shOffset = IO.readOff(mem, offset);
    offset += 4;

    this.shSize = IO.readWord(mem, offset);
    offset += 4;

    this.shLink = IO.readWord(mem, offset);
    offset += 4;

    this.shInfo = IO.readWord(mem, offset);
    offset += 4;

    this.shAddrAlign = IO.readWord(mem, offset);
    offset += 4;

    this.shEntSize = IO.readWord(mem, offset);
    offset += 4;

    return offset;
  }

  /**
   * @return the shName
   */
  public int getShName()
  {
    return this.shName;
  }

  /**
   * @return the shType
   */
  public int getShType()
  {
    return this.shType;
  }

  /**
   * @return the shFlags
   */
  public int getShFlags()
  {
    return this.shFlags;
  }

  /**
   * @return the shAddr
   */
  public int getShAddr()
  {
    return this.shAddr;
  }

  /**
   * @return the shOffset
   */
  public int getShOffset()
  {
    return this.shOffset;
  }

  /**
   * @return the shSize
   */
  public int getShSize()
  {
    return this.shSize;
  }

  /**
   * @return the shLink
   */
  public int getShLink()
  {
    return this.shLink;
  }

  /**
   * @return the shInfo
   */
  public int getShInfo()
  {
    return this.shInfo;
  }

  /**
   * @return the shAddrAlign
   */
  public int getShAddrAlign()
  {
    return this.shAddrAlign;
  }

  /**
   * @return the shEntSize
   */
  public int getShEntSize()
  {
    return this.shEntSize;
  }

  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  @Override
  public String toString()
  {
    return "SectionHeader [shName=" + this.shName + ", shType=" + this.shType
        + ", shFlags=" + this.shFlags + ", shAddr=" + this.shAddr
        + ", shOffset=" + this.shOffset + ", shSize=" + this.shSize
        + ", shLink=" + this.shLink + ", shInfo=" + this.shInfo
        + ", shAddrAlign=" + this.shAddrAlign + ", shEntSize=" + this.shEntSize
        + "]";
  }
  
  
}
